package com.zyz.O_网络编程.UDP.demo1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @author: vick
 * @Date: 2025/4/17
 * @Description:
 * @version: 1.0
 */
public class Send {
    public static void main(String[] args) {
        DatagramSocket datagramSocket = null;
        try {
            datagramSocket = new DatagramSocket();

            byte[] bytes = "hello vick".getBytes();
            DatagramPacket datagramPacket =
                    new DatagramPacket(bytes, 0, bytes.length, InetAddress.getByName("127.0.0.1"), 8888);

            datagramSocket.send(datagramPacket);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            if (datagramSocket != null) {
                datagramSocket.close();
            }
        }
    }
}
